<template>
    <div>
        <div>
            <el-row :gutter="10">
                <el-form :model="searchForm" label-width="100px">
                    <el-col :span="6">
                        <el-form-item label="标题" prop="title">
                            <el-input v-model="searchForm.title"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="奖项简介" prop="describe">
                            <el-input v-model="searchForm.describe"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="评选要求" prop="require">
                            <el-input v-model="searchForm.require"></el-input>
                        </el-form-item>
                    </el-col>                                 
                    <el-col :span="6">
                        <el-form-item label="简介" prop="introduction">
                            <el-input v-model="searchForm.introduction"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="发布时间" prop="created_at">
                            <el-date-picker type="date" placeholder="选择日期" v-model="searchForm.created_at" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </el-col>                          
                    <el-col :span="6">
                        <el-button type="primary" @click="toSearch">搜索</el-button>
                    </el-col>
                </el-form>
            </el-row>
        </div>
        <div class="padding">
            <add-button @click.native="$router.push({path:'/award/add/'})"></add-button>
        </div>
        <el-table :data="dataList" default-expand-all style="width: 100%" row-key="id"
                  :tree-props="{children: 'child'}" :indent="30" v-if="dataList.length > 0">
            <el-table-column label="ID" prop="id"></el-table-column>
            <el-table-column label="标题" prop="title"></el-table-column>
            <el-table-column label="奖项简介" prop="describe"></el-table-column>
            <el-table-column label="评选要求" prop="require"></el-table-column>
            <el-table-column label="奖项设置" prop="setting"></el-table-column>
            <el-table-column label="简介" prop="full_content"></el-table-column>                                  
            <el-table-column label="创建时间" prop="created_at"></el-table-column>
            <!--align:内容对齐，width：单元格宽度-->
            <el-table-column align="right" width="250" label="操作">
                <template slot-scope="scope">
                    <edit-button @click.native="$router.push({path:'/award/edit/'+scope.row.id})"></edit-button>
                    <del-button @click.native="del(scope.row.id)"></del-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="text-center padding-top-bottom-20" v-if="dataList.length > 0">
            <el-pagination
                background
                layout="total,prev, pager, next"
                :page-size="pageSize"
                :current-page.sync="current_page"
                :total="total"
                @current-change="pageChange">
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    name: "AwardList",
    data() {
        return {
            current_page:1,
            pageSize:15,
            total:0,
            content:'',
            dataList: [],
            departmentList:[],
            searchForm: {
                title: '',
                describe: '',
                require: '',
                introduction: '',
                created_at:''                
            },
            rules: {
                
            }
        }
    },
    created() {
        this.searchForm = this.$route.query;
    },
    mounted() {
        this.getList();
    },
    methods:{
        toSearch(){
            this.getList();
        },
        toAdd(){

        },
        getList() {
            let _this = this;
            this.$http.httpPost({
                url:'/api/award',
                datas:{...this.searchForm,current_page:this.current_page},
                success(res){
                    _this.dataList = res.data ? res.data : [];
                    _this.total = res.total;
                }
            })
        },
        pageChange(page) {
            this.current_page = page;
            this.getList();
        },
        del(id) {
            let _this = this;
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.httpPost({
                    url:'/api/award/delete',
                    datas:{"id":id},
                    success(res){
                        _this.$utils.success('删除成功！');
                        _this.getList();
                    }
                })
            }).catch(() => {
                // _this.$utils.warning('取消了');
            });
        }
    }
}
</script>
